package com.ss.android.wenda.c;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.feature.c.FeedContext;
import com.ss.android.article.base.feature.c.FeedPresenter;
import com.ss.android.article.base.feature.feed.FeedOnMovedToScrapHeapListener;
import com.ss.android.article.base.feature.feed.k;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.browser.R;
import com.ss.android.image.loader.LoadImagePolicy;

import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

public class WendaFeedPresenter implements FeedPresenter {
    private Context mContext;
    private Resources mResources;
    private LayoutInflater mLayoutInflater;
    private List d;
    private AtomicBoolean e;
    private int f;
    private int g;

    public WendaFeedPresenter() {

    }

    private View a(int arg8, CellRef arg9, View arg10, ViewGroup arg11) {
        Object v0;
        com.ss.android.wenda.b.a v2;
        View v1 = arg10 == null || ((arg10.getTag() instanceof Stub)) ? arg10 : null;
        if(v1 == null) {
            v1 = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.wd_feed_item, arg11, false);
            v2 = new com.ss.android.wenda.b.a(this.mContext, this.e, this.f, this.g);
            if(v1 != null) {
                v2.o = v1.findViewById(com.ss.android.article.browser.R.id.wd_item_view);
                v2.x = v1.findViewById(com.ss.android.article.browser.R.id.top_padding);
                v2.y = v1.findViewById(com.ss.android.article.browser.R.id.bottom_padding);
                v2.p = v1.findViewById(com.ss.android.article.browser.R.id.wd_title);
                v2.q = v1.findViewById(com.ss.android.article.browser.R.id.wd_answer_count);
                v2.u = v1.findViewById(com.ss.android.article.browser.R.id.wd_answer_content);
                v2.v = v1.findViewById(com.ss.android.article.browser.R.id.wd_answer_name);
                v2.w = v1.findViewById(com.ss.android.article.browser.R.id.wd_answer_zan_count);
                v2.r = v1.findViewById(com.ss.android.article.browser.R.id.wd_feed_small_image);
                v2.s = v1.findViewById(com.ss.android.article.browser.R.id.wd_feed_middle_image);
                v2.t = v1.findViewById(com.ss.android.article.browser.R.id.wd_feed_large_image);
                v2.z = v1.findViewById(com.ss.android.article.browser.R.id.wd_answer_item);
                v2.A = v1.findViewById(com.ss.android.article.browser.R.id.top_line);
                v2.B = v1.findViewById(com.ss.android.article.browser.R.id.bottom_line);
            }

            v1.setTag(v2);
        }
        else {
            v0 = v1.getTag();
            if((v0 instanceof Stub)) {
            }else {
                v2 = new com.ss.android.wenda.b.a(this.mContext, this.e, this.f, this.g);
                v2.C = ((com.ss.android.wenda.b.a) v0).C;
                v2.o = ((com.ss.android.wenda.b.a) v0).o;
                v2.x = ((com.ss.android.wenda.b.a) v0).x;
                v2.y = ((com.ss.android.wenda.b.a) v0).y;
                v2.p = ((com.ss.android.wenda.b.a) v0).p;
                v2.q = ((com.ss.android.wenda.b.a) v0).q;
                v2.u = ((com.ss.android.wenda.b.a) v0).u;
                v2.v = ((com.ss.android.wenda.b.a) v0).v;
                v2.w = ((com.ss.android.wenda.b.a) v0).w;
                v2.r = ((com.ss.android.wenda.b.a) v0).r;
                v2.s = ((com.ss.android.wenda.b.a) v0).s;
                v2.t = ((com.ss.android.wenda.b.a) v0).t;
                v1.setTag(v2);
            }
        }

        v1.setTag(com.ss.android.article.browser.R.id.bo, Integer.valueOf(arg8));
        v0 = v1.getTag();
        try {
            ((com.ss.android.wenda.b.a)v0).a(arg9, arg8, this.d.size());
        }
        catch(Exception v2_1) {
            Logger.throwExceptionInDebug(((Throwable)v2_1));
        }

        if(arg9 != null && arg9.wendaEntity != null) {
            ((com.ss.android.wenda.b.a)v0).a(1, String.valueOf(arg9.wendaEntity.id), "", arg9.logExtra);
        }

        return v1;
    }

    public final int getItemViewType(CellRef cellRef) {
        int v0 = 0;
        if((cellRef.cellFlag & 128) != 0) {
            int v1 = cellRef.cellType;
            if(v1 == 36) {
                v0 = 16;
            }
            else if(v1 == 44) {
                v0 = 18;
            }
            else if(v1 == 43) {
                v0 = 17;
            }
        }

        return v0;
    }

    public final View getView(int position, View convertView, ViewGroup parent) {
        View v0_1;
        View v1 = null;
        if((android.support.design.a.isEmptyCollection((Collection) this.d)) || position < 0 || position >= this.d.size()) {
            v0_1 = v1;
        }
        else {
            Object v0 = this.d.get(position);
            v0_1 = ((CellRef)v0).cellType == 36 ? this.a(position, ((CellRef)v0), convertView, parent) : v1;
            if(v0_1 == null) {
                return v0_1;
            }

            v0_1.setTag(com.ss.android.article.browser.R.id.item_reuse_tag, Boolean.FALSE);
        }

        return v0_1;
    }

    public final void setLastReadClickListener(View.OnClickListener onClickListener) {
    }

    public final void a(View arg3) {
        if(arg3 != null) {
            Object v0 = arg3.getTag();
            if(((v0 instanceof k)) && (((k)v0).d())) {
                ((k)v0).loadImage();
                ((k)v0).e();
            }
        }
    }

    public final void setFeedContext(FeedContext arg6) {
        if(arg6 != null) {
            this.mContext = arg6.mContext;
            this.mResources = this.mContext.getResources();
            this.mLayoutInflater = LayoutInflater.from(this.mContext);
            AppData.getInstance();
            this.d = arg6.mCellRefList;
            this.e = new AtomicBoolean(false);
            int v0 = this.mResources.getDimensionPixelSize(R.dimen.item_image_height);
            int v1 = this.mResources.getDimensionPixelSize(R.dimen.item_image_width);
            this.f = (TTUtils.getScreenWidth(this.mContext) - this.mResources.getDimensionPixelOffset(R.dimen.item_image_total_padding)) / 3;
            this.g = v0 * this.f / v1;
        }
    }

    public final void setLoadImagePolicy(LoadImagePolicy policy) {
    }

    public final void a(boolean arg2) {
        if(this.e.get() != arg2 && (!AppData.getInstance().getAbSettings().shouldLoadImageWhenFling() || !arg2)) {
            this.e.set(arg2);
        }
    }

    public final int getViewTypeCount() {
        return 3;
    }

    public final void onMovedToScrapHeap(View view) {
        if(view != null) {
            Object v0 = view.getTag();
            if(!(v0 instanceof FeedOnMovedToScrapHeapListener)) {
                return;
            }

            try {
                ((FeedOnMovedToScrapHeapListener)v0).onMovedToScrapHeap();
            }
            catch(Exception v0_1) {
                Logger.throwExceptionInDebug(((Throwable)v0_1));
            }
        }
    }

    public final void onHiddenStatusChanged(boolean visible) {
    }

    public final boolean b(CellRef arg2) {
        return false;
    }

    public final void c(boolean arg1) {
    }

    public final void onPrimaryPageChanged(boolean arg1) {
    }

    public final void onDestroy() {
    }

    public final void onResume() {
    }

    public final void f() {
    }

    public final void onPause() {
    }

    public final int g() {
        return 0;
    }

    public final void onStop() {
    }
}

